<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
//购物车控制器
class CartController extends Controller{
//首页
	public function index(){
		
		$data = Cart::getAllData(); 
		View::with('data',$data);
		//sp($data);exit;
		
		View::make();
}
	public function addspe(){
		$coid = Q('post.color');
		$siid = Q('post.size');
		$num = Q('post.num');
		$goodAttr = new \Common\Model\GoodsAttr;
		$color = $goodAttr->where("gtid={$coid}")->pluck("gtvalue");
		$size = $goodAttr->where("gtid={$siid}")->pluck("gtvalue");
		
		$gid = Q('post.gid');
		
		$goodsModel = new \Common\Model\Goods;
		$goodsData = $goodsModel->where("gid={$gid}")->find();
		
		$data = array(
			'id'=>$gid,
			'name'=>$goodsData['gname'],
			'num'=>$num,
			'price'=>$goodsData['shopprice'],
			'options'=>array(
				'color'=>$color,
				'size'=>$size
			)
		);
		Cart::add($data);
		//sp($_SESSION);
	}
		public function del(){
			
		$names = Q('post.names');
		$num = $_SESSION['cart']['goods'][$names]['num'];
		$ntotal = $_SESSION['cart']['goods'][$names]['total'];	
		$znum = $_SESSION['cart']['total_rows'] - $num;		
		$totals = $_SESSION['cart']['total'] - $ntotal;
		unset($_SESSION['cart']['goods'][$names]);
		 $_SESSION['cart']['total'] = $totals;
		 $_SESSION['cart']['total_rows'] = $znum;	 
		$data = array(
			'totals'=>$totals,
			'znum'=>$znum
		);
		echo json_encode($data);
	}
}
